package _01_动态数组;

import java.util.Arrays;

/**
 * https://leetcode-cn.com/problems/maximum-gap/
 * @Author: haogege
 * @Date: 2021/9/5
 */
public class _164_最大间距 {

    public int maximumGap(int[] nums) {
        if (nums.length < 2) return 0;

        // 排序数组
        Arrays.sort(nums);
        // 最大间隙
        int maxGap = nums[1] - nums[0];
        for (int i = 2; i < nums.length; i++) {
            int curGap = nums[i] - nums[i - 1];
            if (curGap > maxGap) {
                maxGap = curGap;
            }
        }
        return maxGap;
    }

}
